package rothag.views.gamestep;

import java.awt.Component;
import java.io.IOException;
import rothag.controller.MainController;
import rothag.enums.EtapeJeu;
import rothag.graphics.*;
import rothag.views.ImageJPanel;
import rothag.views.JPanelBase;
import rothag.views.gamestep.build.ConstruireJPanel;
import rothag.views.gamestep.business.BusinessJPanel;
import rothag.views.gamestep.develop.DeveloppementJPanel;
import rothag.views.gamestep.diceshot.LancerDesJPanel;
import rothag.views.gamestep.endofgame.FinPartieJPanel;
import rothag.views.gamestep.endofturn.FinTourJPanel;
import rothag.views.gamestep.feed.NourrirJPanel;

/**
 * @author Gaetan
 */
public class PartieJPanel extends JPanelBase {

    private InfosTourJPanel infosTour;
    private LancerDesJPanel lancerDes;
    private NourrirJPanel nourrir;
    private ConstruireJPanel construire;
    private BusinessJPanel business;
    private DeveloppementJPanel developpement;
    private FinTourJPanel finTour;
    private FinPartieJPanel finPartie;

    /** Creates new form PartieJPanel */
    public PartieJPanel(MainController controller, ImageJPanel imageJPanel) throws IOException {
        super(controller);

        setOpaque(false);

        // Définition de la taille
        hauteur = GraphicsParameters.partieHeight;
        largeur = GraphicsParameters.partieWidth;

        // Infos tour
        infosTour = new InfosTourJPanel(controller);
        GraphicsHelper.setBounds(0, 0, infosTour);
        //add(infosTour);

        // Lancer des dés
        lancerDes = new LancerDesJPanel(controller);
        //lancerDes.setVisible(false);
        GraphicsHelper.setBounds(0, infosTour.getHeight() + 5, lancerDes);
        //add(lancerDes);

        // Nourrir
        nourrir = new NourrirJPanel(controller);
        //nourrir.setVisible(false);
        GraphicsHelper.setBounds(0, infosTour.getHeight() + 5, nourrir);
        //add(nourrir);

        // Construire
        construire = new ConstruireJPanel(controller);
        //construire.setVisible(false);
        GraphicsHelper.setBounds(0, infosTour.getHeight() + 5, construire);
        //add(construire);

        // Business
        business = new BusinessJPanel(controller);
        //business.setVisible(false);
        GraphicsHelper.setBounds(0, infosTour.getHeight() + 5, business);
        //add(business);

        // Developement
        developpement = new DeveloppementJPanel(controller, imageJPanel.getInfoJoueur().getDeveloppementJPanel().getDeveloppementJList());
        //developpement.setVisible(false);
        GraphicsHelper.setBounds(0, infosTour.getHeight() + 5, developpement);
        //add(developpement);

        // FinTour
        finTour = new FinTourJPanel(controller);
        //finTour.setVisible(false);
        GraphicsHelper.setBounds(0, infosTour.getHeight() + 5, finTour);
        //add(finTour);

        // FinPartie
        finPartie = new FinPartieJPanel(controller, imageJPanel);
        //finPartie.setVisible(false);
        GraphicsHelper.setBounds(0, infosTour.getHeight() + 5, finPartie);
        //add(finPartie);
    }

    public void setEtapeJeu(EtapeJeu etape) {
        for (Component c : getComponents()) {
            remove(c);
        }

        switch (etape) {
            case LANCERDES:
                lancerDes.reset();
                add(lancerDes);
                break;
            case NOURRIR_SELECTION:
                nourrir.reset(NourrirJPanel.MODE_SELECTION);
                add(nourrir);
                break;
            case NOURRIR_INFOS:
                nourrir.reset(NourrirJPanel.MODE_INFOS_ALIMENTATION);
                add(nourrir);
                break;
            case CONSTRUIRE:
                construire.reset();
                add(construire);
                break;
            case COMMERCE:
                business.reset();
                add(business);
                break;
            case DEVELOPPEMENT:
                developpement.reset();
                add(developpement);
                break;
            case DEFAUSSE:
                finTour.reset();
                add(finTour);
                break;
            case FIN_PARTIE:
                finPartie.reset();
                add(finPartie);
                break;
        }

        add(infosTour);

        System.gc();

        /*lancerDes.setVisible(etape == EtapeJeu.LANCERDES);
        nourrir.setVisible(etape == EtapeJeu.NOURRIR_SELECTION || etape == EtapeJeu.NOURRIR_INFOS);
        construire.setVisible(etape == EtapeJeu.CONSTRUIRE);
        business.setVisible(etape == EtapeJeu.COMMERCE);
        developpement.setVisible(etape == EtapeJeu.DEVELOPPEMENT);
        finTour.setVisible(etape == EtapeJeu.DEFAUSSE);
        finPartie.setVisible(etape == EtapeJeu.FIN_PARTIE);*/

        repaint();
    }

    public InfosTourJPanel getInfosTour() {
        return infosTour;
    }

    public LancerDesJPanel getLancerDes() {
        return lancerDes;
    }

    public NourrirJPanel getNourrir() {
        return nourrir;
    }

    public BusinessJPanel getBusiness() {
        return business;
    }

    public ConstruireJPanel getConstuire() {
        return construire;
    }
}
